<div ng-controller="MyorderListC">
    <div class="bg-light lter b-b wrapper-md">
        <h3 class="m-n font-thin h3">我的计划单</h3>
    </div>
    <div class="bg-light lter b-b wrapper-md">
        <div class="row">
            <div class="col-xs-12 input-group" style="padding: 0px 15px 5px">
                <input type="text" class="form-control" id="findname" placeholder="按名称查找" ng-model="findname">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button" ng-click="find('')">查找</button>
                    </span>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-8 btn-group dropdown" dropdown>
                <button class="btn btn-default" dropdown-toggle>按计划单状态查看 <span class="caret"></span></button>
                <ul class="dropdown-menu">
                    <li ng-click="find('')"><a href>查看全部</a></li>
                    <li ng-click="find(0)"><a href>待确认</a></li>
                    <li ng-click="find(1)"><a href>驻厂确认</a></li>
                    <li ng-click="find(2)"><a href>已发货</a></li>
                    <!--<li ng-click="find(3)"><a href>已收货</a></li>-->
                    <li ng-click="find(4)"><a href>已结算</a></li>
                    <!--<li ng-click="find(5)"><a href>完结</a></li>-->
                    <li ng-click="find(6)"><a href>取消</a></li>
                    <li ng-click="find(7)"><a href>审核通过</a></li>
                    <!--<li ng-click="find(8)"><a href>已退货</a></li>
                    <li ng-click="find(9)"><a href>已退款</a></li>-->
                </ul>
            </div>
            <!--<div class="col-xs-4 btn-group">-->
                <!--<button class="btn btn-default" ng-click="add()">新建计划单</button>-->
            <!--</div>-->
            <div class="col-xs-4 btn-group">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    新建计划单 <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li ng-click="add(4)"><a>库提计划单</a></li>
                    <li ng-click="add(0)"><a>直采计划单</a></li>
                    <li ng-click="add(2)"><a>贸易商</a></li>
                </ul>
            </div>
        </div>
    </div>
        <a ng-click="xxx($index)" ng-repeat="item in orders">
    <div class="panel panel-default" style="margin-bottom: 10px">
        <div class="panel-heading">
            <h3 class="panel-title">{{item.Customer.Name}}</h3>
        </div>
        <div class="panel-body">
            <div class="row">
            <div class="col-xs-6"><strong>地址：</strong>{{item.District.Name}}</div>
            <div class="col-xs-6">
            <strong>状态：</strong>
            <span ng-if="item.State == 0">待确认</span>
            <span ng-if="item.State == 1">驻厂确认</span>
            <span ng-if="item.State == 2">已发货</span>
            <span ng-if="item.State == 3">已收货</span>
            <span ng-if="item.State == 4">已结算</span>
            <span ng-if="item.State == 5">完结</span>
            <span ng-if="item.State == 6">取消</span>
            <span ng-if="item.State == 7">审核通过</span>
            <span ng-if="item.State == 8">已退货</span>
            <span ng-if="item.State == 9">已退款</span>
            </div>
            </div>
            <div class="row">
            <div class="col-xs-6"><strong>金额/重量t：</strong>{{item.Total | number:2}}/{{item.Weight | number:3}}t</div>
            <div class="col-xs-6">
            <strong>标注：</strong>
            <span ng-if="item.IsFullPayment">先款支付</span>&nbsp;
            <span ng-if="item.IsStandard">标件</span>
            </div>
            </div>
            <div class="row">
            <div class="col-xs-6">
            <strong>已付金额：</strong>{{item.Prepayments | number:2}}
            </div>
            <span class="col-xs-6" ng-if="item.Prepayments >= item.Total&&item.State!=6 ">账款已付清</span>
            <span style="color: red" class="col-xs-6" ng-if="item.Prepayments < item.Total&&item.State!=6">账款未付清</span>
            </div>
            <div class="row">
                <div class="col-xs-6"><strong>备注：</strong>{{item.Remarks}}</div>
                <div>
                    <span class="col-xs-6" ng-if="item.PaidDelivery >= item.DeliveryPriceTotal&&item.State!=6">运费已付</span>
                    <span style="color: red" class="col-xs-6" ng-if="item.PaidDelivery < item.DeliveryPriceTotal &&item.State!=6">运费未付</span>
                </div>
            </div>
        </div>
        <div class="panel-footer">{{item.CreateTime}}</div>
    </div>
            </a>
    <div class="row text-center">
        <div class="panel-heading" my-pagination get-page-data="getData" mypagedata="pageData"></div>
    </div>
</div>



<script>
    angular.module('app') //锁价单列表控制器
    .controller("MyorderListC", function ($scope, $state, $http,toSave) {
        $scope.pageData = {};
        $scope.pageData.Page = 0;
        $scope.state = "";
        $scope.findname = "";
        $scope.pageData.Rows = $scope.defPageRows;
        $scope.getData = function (p, r) {
            if (p) {
                p = p < 1 ? 1 : p;
            } else p = 1;
            if (r) {
            } else r = $scope.defPageRows;
            toSave.save_pages_lis(p,r);//保存当前页码和条数
            console.log(toSave.get_pages(),toSave.get_lis());
            $http({
                url: "../api/ClientManager/OrderList?page=" + p + "&rows=" + r + "&state=" + $scope.state + "&keyword="+ $scope.findname,
                method: "GET"
            })
            .then(function (res) {
                $scope.orders = res.data.Data;
                $scope.pageData = res.data;
            })
            .then(function (error) {
                if (error) {
                    alert("数据获取失败");
                }
            });
        };
        $scope.xxx = function (index) {
            $state.go('app.Order_MyDetail', {
                orderid: JSON.stringify($scope.orders[index].Id)
            });
        };
        $scope.add = function (type1) {
            $state.go('app.Order_Add',{
                type: JSON.stringify(type1)
            });
        };
        //加载数据
        // $scope.getData(toSave.get_pages(), $scope.pageData.Rows);
        $scope.find = function (state) {
            if(state || state == ''){
                $scope.state=state;
            }
            localStorage.setItem('c',$scope.state)
            $scope.getData(1, $scope.pageData.Rows);
            toSave.save_inputs();//点击查询先保存input里面的值
            console.log(toSave.get_inputs('findname'))
        };
        console.log(11)
        if (toSave.get_inputs('findname') || localStorage.getItem('c') !=null) {
                    $scope.findname=toSave.get_inputs('findname');//把保存该id名的值取出来赋值给input框
                    // alert(111);
                    $scope.state=localStorage.getItem('c')
                    $scope.getData(toSave.get_pages(), toSave.get_lis());
                    console.log(toSave.get_pages(), toSave.get_lis());
         }else{
                    $scope.getData(toSave.get_pages(), $scope.pageData.Rows);
         }
    })
</script>
<script src="js/services/toSave.js"></script>
